<?php

namespace app\controller\web;

use app\exception\ErrnoPlus;
use app\service\TutorialVideoService;
use app\validate\TutorialVideoValidate;

use app\validate\PageValidate;
use share\exception\ApiException;
use share\utils\Helper;

class TutorialVideoController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new TutorialVideoValidate();
    }

    /**
     * 新增视频教程
     */
    public function add_action(){
        $input = $this->check();
        $data = TutorialVideoService::addVideo($input);
        return self::ok($data);
    }

    /**
     * 修改视频教程
     */
    public function edit_action(){
        $input = $this->check();
        $data = TutorialVideoService::updateVideo($input);
        return self::ok($data);
    }

    /**
     * 删除视频教程
     */
    public function del_action(){
        $input = $this->check();
        $data = TutorialVideoService::delVideo($input['id']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){        
        $page = $this->check('pageInfo',null,(new PageValidate()));
        $input = $this->check();       
        $data = TutorialVideoService::getListInfo($input,$page);
        $data = Helper::arrayListReplaceKey($data,[
            'default_picture' => 'defaultPicture',
            'model_id'=> 'modelId',
            'title_id'=> 'titleId',
            'create_time' => 'createTime',
            'update_time' => 'updateTime',
        ]);
        $total = TutorialVideoService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }

}